package main

import (
	"fmt"
	"time"

	//pb "grpc-demo/protoc"

	pb "gitee.com/segeln/grit/example/protoc"
	//	"gitee.com/segeln/grit/registry"

	//	consule "gitee.com/segeln/grit/registry/consule"

	//	"gitee.com/segeln/grit/registry/healthcheck"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
)

const (
//Address = "127.0.0.1:9001"
)

var (
//reg = consule.NewConsulRegistry("127.0.0.1:8500")
)

func main() {
	//reg.Init()
	//sinfos, err := getServiceAddress()
	//for info := range sinfos {
	//	fmt.Println("address:", info)
	//}
	//	fmt.Println("address:", address)
	conn, err := grpc.Dial("127.0.0.1:9010", grpc.WithInsecure())
	if err != nil {
		fmt.Println(err)
	}
	defer conn.Close()
	for i := 0; i < 1; i++ {

		//初始化客户端
		c := pb.NewHelloClient(conn)

		req := new(pb.HelloReq)
		req.Req = "hello222"
		r, err := c.SayHello(context.Background(), req)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(r.Rep)

		r, err = c.CallHello(context.Background(), req)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(r.Rep)

		fmt.Println("-----------------------")
		time.Sleep(time.Second * 3)
	}

}

//func (c *helloClient) SayHello(ctx context.Context, in *HelloReq, opts ...grpc.CallOption) (*HelloRep, error) {

type ClientFun func(context.Context, interface{}, ...grpc.CallOption) (interface{}, error)

//func getServiceAddress() ([]registry.ServiceInfo, error) {
//return reg.GetServices("user")
//}
